package com.yc.ServerClient;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;

public class Test2_client {
    public static void main(String[] args) throws IOException {
        //编写一个客户端
        InetAddress[] ia2=InetAddress.getAllByName("www.baidu.com");
        if(ia2!=null){
            //baidu服务器的IP有多个
            for(InetAddress ia:ia2){
//                System.out.println(ia);
                Socket client=new Socket(ia,80);
                System.out.println("联接成功！"+client);//Socket[addr=www.baidu.com/153.3.238.110,port=80,localport=64615]
                                                      //基于TCP的客户端套接字对象                              本机的发送端口
                //本地端口一般是随机的 localport=64615 会变化
                break;
            }
        }
        Socket client2=new Socket("www.baidu.com",80);
        System.out.println("联接成功2！"+client2);

        Socket client3=new Socket("45.113.192.102",80);
        System.out.println("联接成功3！"+client3);
    }

}
